import {
	mapState
} from 'vuex'

export default {

	computed: {
		...mapState('m_chat', ['topMsgData', 'notTopMsgData']),
	},
	watch: {
		topMsgData() {
			//console.log(123)
			this.setBadge()
		},
		notTopMsgData() {
			//console.log(123)
			this.setBadge()
		}
	},
	onShow() {
		this.setBadge()
	},
	methods: {
		setBadge() {
			var allMsgNum = 0;

			for (var i = 0; i < this.topMsgData.length; i++) {
				allMsgNum += this.topMsgData[i].msgNum
			}

			for (var i = 0; i < this.notTopMsgData.length; i++) {
				allMsgNum += this.notTopMsgData[i].msgNum
			}
			//console.log(allMsgNum)
			if (allMsgNum != 0) {
				uni.setTabBarBadge({
					index: 2,
					text: allMsgNum + ''
				})
			} else {
				setTimeout(() => {
					// uni.removeTabBarBadge({
					// 	index: 2
					// })

					uni.hideTabBarRedDot({
						index: 2
					});
				}, 10);

			}
		}
	}
}